package io.renren.modules.sys.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.sys.entity.SysCodetypeEntity;
import io.renren.modules.sys.service.SysCodetypeService;

/**
 * @author chaolemen
 * @email 2698481037@qq.com
 * @date 2017-12-24 20:58:13
 */
@RestController
@RequestMapping("/sys/syscodetype")
public class SysCodetypeController {
	@Autowired
	private SysCodetypeService sysCodetypeService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sys:syscodetype:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<SysCodetypeEntity> sysCodetypeList = sysCodetypeService.queryList(query);
		int total = sysCodetypeService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(sysCodetypeList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sys:syscodetype:info")
	public R info(@PathVariable("id") Long id){
		SysCodetypeEntity sysCodetype = sysCodetypeService.queryObject(id);
		
		return R.ok().put("sysCodetype", sysCodetype);
	}
	
	/**
	 * 信息
	 */
	@RequestMapping("/all")
	@RequiresPermissions("sys:syscodetype:info")
	public R all(){
		List<SysCodetypeEntity> sysCodetypeList = sysCodetypeService.queryList(null);
		return R.ok().put("sysCodetypeList", sysCodetypeList);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sys:syscodetype:save")
	public R save(@RequestBody SysCodetypeEntity sysCodetype){
		sysCodetypeService.save(sysCodetype);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sys:syscodetype:update")
	public R update(@RequestBody SysCodetypeEntity sysCodetype){
		sysCodetypeService.update(sysCodetype);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sys:syscodetype:delete")
	public R delete(@RequestBody Long[] ids){
		sysCodetypeService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
